home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 003 / tcdbf.arc / D_PUTFLD.C < prev    next >
Text File  |  1987-06-14  |  1KB  |  43 lines

  1. /* 
  2. **        file:        d_putfld.c
  3. **        purpose:    routine to fill a field with data from buffer.
  4. **        ussage:    d = (struct DBF *)malloc(sizeof(struct DBF));
  5. **                    strcpy(d->filename,"filename.dbf");
  6. **                    d_open(d);
  7. **                    d_getrec(d,(long)recordno);
  8. **                    d_getfld(d,fieldno,buffer);
  9. **                    ... modify field data ...
  10. **                    d_putfld(d,fieldno,buffer);
  11. **                    d_putrec(d,(long)recordno);
  12. **                    d_close(d);
  13. **                    free(d);
  14. **        notes:    compile with "tcc -c d_putfld".    include this file in dbf.li
  15. **                    see dbf.h for structure of DBF.    this routine places the data into
  16. **                    a record in memory.    d_addrec or d_putrec must be called to write
  17. **                    the data to the file on disk.
  18. **        returns:    length of the field if successful. 0 if not.
  19. **        author:    Mark Sadler
  20. **        revised:    6/14/87
  21. */ 
  22.  
  23. #include <stdio.h>
  24. #include <mem.h>
  25. #include "dbf.h"
  26.  
  27. int d_putfld(struct DBF *d,int f,char *buff)
  28. {
  29.     struct FIELD_RECORD *fp;
  30.  
  31.     if(f > 0 && f <= d->num_fields)
  32.         {
  33.         fp = d->fields_ptr + (f - 1);
  34.         memcpy(fp->field_data_address,buff,fp->len);
  35.         return(fp->len);
  36.         }
  37.     else
  38.         {
  39.         return(0);
  40.         }
  41. }
  42.  
  43.